package com.example.zzl.model.bean.SearchFragment;

import android.util.Log;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.zzl.app.MyApplication;
import com.google.gson.Gson;

import java.util.ArrayList;

/**
 * Created by zhang on 2017/2/11.
 */

public class LoadMateData {
    private Data data;

    public LoadMateData(Data data,String url) {
        this.data = data;
        loadData(url);
    }

    private void loadData(String url) {
        StringRequest request = new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                ArrayList lists = new Gson().fromJson(response,ArrayList.class);
                ArrayList<SearchMate> mates = new ArrayList<>();
                for (int i = 0; i < lists.size(); i++) {
                    SearchMate mate = new Gson().fromJson(new Gson().toJson(lists.get(i)),SearchMate.class);
                    mates.add(mate);
                }
                data.sendMateData(mates);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        MyApplication.queue.add(request);
    }
}
